package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Salary;
import cn.wolfcode.crm.mapper.SalaryMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISalaryService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SalaryServiceImpl implements ISalaryService {

    @Autowired
    private SalaryMapper salaryMapper;

    //保存和更新员工操作
    public int saveOrUpdate(Salary record) {
        if (record.getId() == null) {
            return salaryMapper.insert(record);
        } else {
            return salaryMapper.updateByPrimaryKey(record);
        }
    }

    //查询单个员工操作
    public Salary selectByPrimaryKey(Long id) {
        return salaryMapper.selectByPrimaryKey(id);
    }


    //员工列表操作
    public List<Salary> selectAll() {
        return salaryMapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int count = salaryMapper.queryCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Salary> data = salaryMapper.queryList(qo);
        return new PageResult(count, data);
    }
}
